package com.qianfeng.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import com.qianfeng.commons.DBManager;
import com.qianfeng.commons.DBUtils;
import com.qianfeng.dao.IGoodsInfoDao;
import com.qianfeng.entity.GoodInfo;
import com.qianfeng.entity.User;

public class GoodsInfoDaoImpl extends DBUtils<GoodInfo> implements IGoodsInfoDao {

	@Override
	public List<GoodInfo> queryAllGoodsInfo() {
		String sql = "SELECT * from t_goods_info WHERE isdelete = '否'";
		return super.getList(sql, GoodInfo.class);
	}

	@Override
	public GoodInfo queryGoodInfoById(int goodId) {
		String sql = "SELECT * from t_goods_info WHERE id = ?";
		return super.getSingleInstance(sql, GoodInfo.class, goodId);
	}

	@Override
	public int querycount() {
		String sql="SELECT count(*) from t_goods_info";
		int count=0;
		Connection connection = DBManager.getConnection();
		try {
			Statement st = connection.createStatement();
			
			ResultSet rs = st.executeQuery(sql);
			while(rs.next())
			count =rs.getInt(1);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally{
			try {
				connection.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return count;
	}

	@Override
	public List<GoodInfo> queryfenye(int rowIndex, int pageSize) {
		String sql= "select * from t_goods_info limit ?,?";
		return super.getList(sql, GoodInfo.class, rowIndex,pageSize);
	}

	@Override
	public int updateGoodInfo(GoodInfo goodInfo) {
		String sql = "update t_goods_info set goods_name = ?,goods_description = ? ,goods_price=?,goods_stock=?,goods_fatherid=?,goods_parentid=? where id = ?";
		return super.commonOper(sql, goodInfo.getGoods_name(),goodInfo.getGoods_description(),goodInfo.getGoods_price(),goodInfo.getGoods_stock(),goodInfo.getGoods_fatherid(),goodInfo.getGoods_parentid(),goodInfo.getId());
	}

	@Override
	public int deleteByid(int id) {
		String sql = "delete from t_goods_info where id = ?";
		return commonOper(sql, id);
	}

	

}
